package com.yunxi;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;   
import org.apache.http.client.HttpClient;    
import org.apache.http.client.methods.HttpPost;  
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;   

public class ClientMain {

	@SuppressWarnings("unused")
    public static void main(String[] args) {
		String url ="http://localhost:9080/esb/api/receive";
		String jsonStr ="{\"lists\":[{\"kunnr\":\"LS001\",\"vkorg\":\"AS51\",\"sdabw\":\"\",\"bstkd\":\"TEST-ZCLT1\",\"vbeln\":\"0084000006\",\"posnr\":10,\"vhvin\":\"AC20190404KW00004\",\"matnr\":\"AM861BFMCHL19B0\",\"colorid\":\"WP01\",\"colorin\":\"NNGA\",\"lfimg\":1.000,\"unit\":\"EA\",\"werks\":\"AS11\",\"wadatist\":\"2019-06-03\",\"lgort\":\"VW01\",\"dealeradd\":\"虚拟地址\",\"lfart\":\"ZLR1\",\"erdat\":\"2019-06-03\",\"erzet\":\"15:30:04\",\"vsbed\":\"01\",\"vsart\":\"\",\"conname\":\"\",\"telf1\":\"\",\"indicator\":\"I\"	},{\"kunnr\":\"LS001\",\"vkorg\":\"AS51\",\"sdabw\":\"\",\"bstkd\":\"TEST-ZCLT2\",\"vbeln\":\"0084000007\",\"posnr\":10,\"vhvin\":\"AC20190404KW00004\",\"matnr\":\"AM861BFMCHL19B0\",\"colorid\":\"WP01\",\"colorin\":\"NNGA\",\"lfimg\":1.000,\"unit\":\"EA\",\"werks\":\"AS11\",\"wadatist\":\"2019-06-04\",\"lgort\":\"VW01\",\"dealeradd\":\"虚拟地址\",\"lfart\":\"ZLR1\",\"erdat\":\"2019-06-04\",\"erzet\":\"10:44:36\",\"vsbed\":\"01\",\"vsart\":\"\",\"conname\":\"\",\"telf1\":\"\",\"indicator\":\"I\"	},{\"kunnr\":\"DEALER001\",\"vkorg\":\"AS51\",\"sdabw\":\"\",\"bstkd\":\"test0402\",\"vbeln\":\"0800000030\",\"posnr\":10,\"vhvin\":\"AC20190404KW00002\",\"matnr\":\"AM861BFMCHL19B0\",\"colorid\":\"WP01\",\"colorin\":\"NNGA\",\"lfimg\":1.000,\"unit\":\"EA\",\"werks\":\"AS11\",\"wadatist\":\"2019-04-02\",\"lgort\":\"\",\"dealeradd\":\"上海长阳创谷\",\"lfart\":\"ZLF1\",\"erdat\":\"2019-05-09\",\"erzet\":\"13:28:14\",\"vsbed\":\"01\",\"vsart\":\"\",\"conname\":\"\",\"telf1\":\"\",\"indicator\":\"I\"	},{\"kunnr\":\"DEALER001\",\"vkorg\":\"AS51\",\"sdabw\":\"\",\"bstkd\":\"test0513\",\"vbeln\":\"0800000035\",\"posnr\":10,\"vhvin\":\"AC20190404KW00003\",\"matnr\":\"AM861BFMCHL19A0\",\"colorid\":\"WB01\",\"colorin\":\"NNGA\",\"lfimg\":1.000,\"unit\":\"EA\",\"werks\":\"AS11\",\"wadatist\":\"2019-05-13\",\"lgort\":\"VW01\",\"dealeradd\":\"上海长阳创谷\",\"lfart\":\"ZLF1\",\"erdat\":\"2019-05-13\",\"erzet\":\"14:39:47\",\"vsbed\":\"01\",\"vsart\":\"\",\"conname\":\"\",\"telf1\":\"\",\"indicator\":\"I\"	},{\"kunnr\":\"DEALER001\",\"vkorg\":\"AS51\",\"sdabw\":\"A\",\"bstkd\":\"PMS20190523001\",\"vbeln\":\"0800000041\",\"posnr\":10,\"vhvin\":\"T032\",\"matnr\":\"AM861BFMCHL19A0\",\"colorid\":\"WB01\",\"colorin\":\"NNGA\",\"lfimg\":1.000,\"unit\":\"EA\",\"werks\":\"AS11\",\"wadatist\":\"2019-05-23\",\"lgort\":\"VW01\",\"dealeradd\":\"上海市杨浦区\",\"lfart\":\"ZLF1\",\"erdat\":\"2019-05-23\",\"erzet\":\"18:20:31\",\"vsbed\":\"01\",\"vsart\":\"\",\"conname\":\"\",\"telf1\":\"\",\"indicator\":\"I\"	},{\"kunnr\":\"DEALER001\",\"vkorg\":\"AS51\",\"sdabw\":\"1\",\"bstkd\":\"PMS20190523001\",\"vbeln\":\"0800000044\",\"posnr\":10,\"vhvin\":\"T030\",\"matnr\":\"AM861BFMCHL19A0\",\"colorid\":\"WB01\",\"colorin\":\"NNGA\",\"lfimg\":1.000,\"unit\":\"EA\",\"werks\":\"AS11\",\"wadatist\":\"2019-05-23\",\"lgort\":\"W800\",\"dealeradd\":\"上海市杨浦区\",\"lfart\":\"ZLF1\",\"erdat\":\"2019-05-25\",\"erzet\":\"14:37:23\",\"vsbed\":\"01\",\"vsart\":\"\",\"conname\":\"\",\"telf1\":\"\",\"indicator\":\"I\"	}]}";


        String contentType = "application/json";
String res=ClientMain.sendPost(url,jsonStr,contentType);
		System.out.println(res);
	}

	public static String sendPost(String url,String bodyStr,String contentType) {  
        StringBuffer resultBuffer = null;  
        HttpClient client = new DefaultHttpClient();  
        HttpPost httpPost = new HttpPost(url);
        httpPost.addHeader("Content-Type", contentType);
        httpPost.addHeader("requestId", "35b8d072-baae-11e6-9e71-0a0a012d6555");
        httpPost.addHeader("serviceName", "S0220002A");
        httpPost.addHeader("sourceSystem", "ERP");
        BufferedReader br = null;  
        try {  
        	StringEntity entity = new StringEntity(bodyStr, "UTF-8");
            httpPost.setEntity(entity);
            HttpResponse response = client.execute(httpPost); 
            resultBuffer = new StringBuffer();  
            br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));  
            String temp;  
            while ((temp = br.readLine()) != null) {  
                resultBuffer.append(temp);  
            }  
        } catch (Exception e) {  
            throw new RuntimeException(e);  
        } finally {  
            if (br != null) {  
                try {  
                    br.close();  
                } catch (IOException e) {  
                    br = null;  
                    throw new RuntimeException(e);  
                }  
            }  
        }  
        return resultBuffer.toString();  
    }  
}
